package io;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

/**
 * reead write 都可能会阻塞 wait
 */
public class PipeTest1 {
    public static void main(String[] args) throws IOException {
        PipedOutputStream out = new PipedOutputStream();
        PipedInputStream in = new PipedInputStream(out);

        String s = "hahahehexixixi";
        byte[] b = s.getBytes();
        byte[] b2 = new byte[b.length];
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
            out.write(b);
        }

        int read = in.read(b2);

        System.out.println(b.length);
        System.out.println(read);
        System.out.println(new String(b2));
    }
}
